<?php

require_once  __DIR__ . '/includes/authenticate.php';
include_once './db_bb_connect.php';

?>



<div id="addtrainingsgeninfocontent">

<h4>Add General Training Info</h4>

<form>

<select class="form-control"  name="season">
		
<?php

if (isset($_POST['season'])) {

	$setseason = $_POST['season'];

	echo  "<option selected=\"selected\" value=\"$setseason\"> $setseason is selected</option>";
	
} else {
	echo  "<option selected=\"selected\" disabled=\"disabled\"> Select season</option>";
}


$sql = "SELECT season 
FROM seasons";

$result = $db->query($sql);

while ($row = $result->fetch_assoc()) {
	$season = $row['season'];

	echo "<option value=\"$season\"> $season </option>";
}

?>
</select>
<br>

<input class="form-control" type="date" name="date" placeholder="date of training YYYY-MM-DD" />
<br>
<input class="form-control" type="text" name="subjects" placeholder="topics covered in training" />
<br>
<textarea class="form-control" name="comment" placeholder="general impressions of the training"></textarea>

<br>

<button class="form-control btn btn-success" id="trainingaddgeninfosubmitbutton" type="submit">Add</button>
</form>

<script type="text/javascript">
	

$("#trainingaddgeninfosubmitbutton").on("click", function(e) {
    postData = $(this.form).serialize();
    $.ajax({
        type: "POST",
        url: "./includes/handlers/training_addgeninfo_handler.php",
        data: postData,
        success: function(data) { 
            $("#addtrainingsgeninfocontent").html(data); 
        },
        error: function (xhr, status, error) {
        	$("#addtrainingsgeninfocontent").html(xhr.responseText); 
        }
      }); 
    e.preventDefault();
});  

</script>